#pragma once

#include "iterator.h"

namespace sfc::iter {

template <class I>
struct Rev {
  using Item = typename I::Item;
  I _inn;

 public:
  [[sfc_inline]] auto len() const -> usize {
    return _inn.len();
  }

  [[sfc_inline]] auto next() -> option::Option<Item> {
    return _inn.next_back();
  }

  [[sfc_inline]] auto next_back() -> option::Option<Item> {
    return _inn.next();
  }

  [[sfc_inline]] auto operator->() -> Iter<Rev>* {
    return static_cast<Iter<Rev>*>(this);
  }
};

template <class I>
auto Iter<I>::rev() {
  return Rev<I>{static_cast<I&&>(*this)};
}

}  // namespace sfc::iter
